using System;
using System.Collections;
using System.Collections.Generic;
using DG.Tweening;
using TMPro;
using UnityEngine;
using UnityEngine.UI;


public class InfoPanel : BasePanel
{
    public Image healthImg;
    private Player player;
    public float widthDuration = 0.5f;
    public TextMeshProUGUI healthTxt;
    public float healthWidth = 650f;
    private void Start()
    {
        
    }

    public override void OpenPanel(string name, params object[] args)
    {
        base.OpenPanel(name, args);
        player = GameManager.Instance.player.GetComponent<Player>();
    }

    public override void ClosePanel()
    {
        base.ClosePanel();
    }

    public void UpdateHealthImg(int curHealth)
    {
        float targetWidth = 0f;
        if (player.health == curHealth)
        {
            targetWidth = healthWidth;
        }
        else
        {
            targetWidth = (float)curHealth / player.health * healthWidth;
        }

        // 保持高度不变，仅修改宽度
        Vector2 targetSize = new Vector2(targetWidth, healthImg.rectTransform.sizeDelta.y);
        healthImg.rectTransform.DOSizeDelta(targetSize, widthDuration).SetEase(Ease.OutQuad); // 添加缓动效果
        healthTxt.text = curHealth + "/" + player.health;
    }
}